<?php

include('loaddb.php');

$output=array();
if (isset($_GET['getglobal']))
{
	$result=$mysql->query("select scanid,hostid,hostname,totalsize from host_stats join hosts on (host_stats.hostid=hosts.id) order by lower(hostname),scanid");
#	$result=$mysql->query("select scanid,hostid,hostname,numsharedfiles from host_stats join hosts on (host_stats.hostid=hosts.id) order by lower(hostname),scanid");
	while ($myrow=$result->fetch_array())
	{		
		$hostid="host".$myrow['hostid'];
		$hostname=$myrow['hostname'];
		$scanid=$myrow['scanid'];
		$size=$myrow['totalsize'];
#		$size=$myrow['numsharedfiles'];
		$objects[$hostid][$scanid]=$size;
		if (!isset($objectnames[$hostid]))
			$objectsorder[]=$hostid;		// only add it to the ordered list if 
		$objectnames[$hostid]=$hostname;
	}
	$output['global']=$objects;
	$output['globalnames']=$objectnames;
	$output['globalorder']=$objectsorder;
}

if (isset($_GET['getscans']))
{
	$result=$mysql->query("select id,unix_timestamp(time) from scans order by time");
	while ($myrow=$result->fetch_array())
	{
		$scans[$myrow[0]]=$myrow[1];
	}
	$output['scans']=$scans;
}

if (isset($_GET['getnowtime']))
{
	$output['nowtime']=time();
}
	
print json_encode($output);
